package com.yf1706.service;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yf1706.bean.CheckAffairApply;
import com.yf1706.bean.CheckComputeRule;
import com.yf1706.bean.CheckRule;
import com.yf1706.dao.jpa.ICheckComputeRuleJDAO;
import com.yf1706.dao.jpa.ICheckRuleJDAO;
import com.yf1706.dao.mybatis.ICheckRuleMDAO;
import com.yf1706.vo.checkRuleVO;
import com.yf1706.vo.upCheckRuleVO;

@Service
@Transactional(rollbackFor=Exception.class)
public class checkRuleService {
	@Autowired
	private ICheckRuleMDAO crMdao;
    @Autowired
    private ICheckRuleJDAO crJdao;
    @Autowired
    private ICheckComputeRuleJDAO ccrJdao;
	public List<CheckRule> getcheckRuleList(){
		return crMdao.queryCheckrule();
	}
	public List<CheckRule> getcheckRuleList(int id){
		return crMdao.queryCheckrules(id);
	}
	//根据条件模糊查询
	public List<CheckRule> serchcheckRuleList(String ruleName){
		return crMdao.qureyRuleList(ruleName);
	}
	public void addCheckRule(checkRuleVO crVO) {
		CheckComputeRule ccr=ccrJdao.findBycomputeId(crVO.getComputId());
		CheckRule cr= new CheckRule();
		cr.setClockIn(crVO.getClockIn());
		cr.setInbeginTime(crVO.getInbeginTime());
		cr.setInendTime(crVO.getInendTime());
		cr.setClockLate(crVO.getClockLate());
		cr.setLatebeginTime(crVO.getLatebeginTime());
		cr.setLateendTime(crVO.getLateendTime());
		cr.setEarlyClock(crVO.getEarlyClock());
		cr.setEarlybeginTime(crVO.getEarlybeginTime());
		cr.setEarlyendTime(crVO.getEarlyendTime());
		cr.setClockOut(crVO.getClockOut());
		cr.setOutbeginTime(crVO.getOutbeginTime());
		cr.setOutendTime(crVO.getOutendTime());
		cr.setRemark(crVO.getRemark());
		cr.setMaker(crVO.getMaker());
		cr.setMakeTime(new Date());
		cr.setCheckComputeRule(ccr);
		cr.setState("是");
		crJdao.save(cr);
	}
	public void updateCheckRule(upCheckRuleVO crVO) {
		CheckRule cr1=new CheckRule();
		CheckComputeRule ccr1=ccrJdao.findBycomputeId(crVO.getComputId());
		cr1.setClockIn(crVO.getClockIn());
		cr1.setInbeginTime(crVO.getInbeginTime());
		cr1.setInendTime(crVO.getInendTime());
		cr1.setClockLate(crVO.getClockLate());
		cr1.setLatebeginTime(crVO.getLatebeginTime());
		cr1.setLateendTime(crVO.getLateendTime());
		cr1.setEarlyClock(crVO.getEarlyClock());
		cr1.setEarlybeginTime(crVO.getEarlybeginTime());
		cr1.setEarlyendTime(crVO.getEarlyendTime());
		cr1.setClockOut(crVO.getClockOut());
		cr1.setOutbeginTime(crVO.getOutbeginTime());
		cr1.setOutendTime(crVO.getOutendTime());
		cr1.setRemark(crVO.getRemark());
		cr1.setMaker(crVO.getMaker());
		cr1.setMakeTime(crVO.getMakeTime());
		cr1.setCheckComputeRule(ccr1);
		cr1.setState("是");
		crJdao.save(cr1);
	}
	public void deleteCheckRule(int id) {
		crJdao.deleteById(id);
	}
}
